class ListNode:
    def __init__(self):
        self.next:ListNode = None
        self.val:int

l1 = ListNode()  
l1.val = 1
l2 = ListNode()
l2.val = 2
l3 = ListNode()
l3.val = 3

l1.next = l2
l2.next = l3    #   1       2       3
                #   l1      l2      l3 


def Invert(head:ListNode) -> ListNode:
    current = head
    previous = None

    while current!=None:
        previous = current
        current = current.next
        current.next = previous

if __name__ == "__main__":
    l = l1
    while l != None:
        print(l.val) 
        l = l.next
    
    Invert(l1)
    ll = l1
    while ll != None:
        print(ll.val)
        ll = ll.next
        